using System;

namespace Nirvana
{
    public abstract class CSharpSingletion<T> where T : class, new()
    {
        protected static T _Instance = null;

        public static T Instance
        {
            get
            {
                if (null == _Instance)
                {
                    _Instance = new T();
                }
                return _Instance;
            }
        }

        protected CSharpSingletion()
        {
            if (null != _Instance)
                throw new Exception("This " + (typeof(T)).ToString() + " Singleton Instance is not null !!!");
            Init();
        }


        protected virtual void Init()
        {

        }
        public void Dispose()
        {
            OnDipose();
            _Instance = null;
        }

        protected virtual void OnDipose()
        {

        }
    }
}